import { NoSkinCellRenderer } from "../../common/item/NoSkinCellRenderer";
import { SPlaceInfo } from "../../../../../Message/Game/SPlaceInfo";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { PetIslandUtil } from "../PetIslandUtil";
import { RemainTimeUtil } from "../../shopMall/RemainTimeUtil";
import { Language } from "../../../../../extend/language/Language";
import { Cache } from "../../../cache/Cache";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GBitmap } from "../../../../../com/mui/controls/GBitmap";
//class PetIslandMapDiscardItemRenderer
    
    export  class PetIslandMapDiscardItemRenderer extends NoSkinCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            if (typeof arg1 === "splaceinfo") 
            {
                this._vo = arg1 as SPlaceInfo;
                this._name.htmlText = GameDefConfig.instance.getPetIslandName(this._vo.pos.isLand) + " · " + GameDefConfig.instance.getPetIslandPlaceTypeName(this._vo.pos.placeType);
                this._position.htmlText = PetIslandUtil.getPosName(this._vo.pos, false);
                this._output.text = this._vo.grassRemain.toString();
                this._time.text = this._vo.occupySeconds > 0 ? RemainTimeUtil.getRemainMinute(this._vo.occupySeconds, true, true, true, false, true) : 0 + Language.getString(35609);
                this._time.textColor = Cache.instance.petIsland.attackItem.placeId != this._vo.placeId ? GlobalStyle.color5Uint : GlobalStyle.color7Uint;
                this._speed.text = Language.getStringByParam(28183, this._vo.exploitSpeed);
                this._income.text = this._vo.grassCount.toString();
                this.setBg();
            }
            return;
        }

        /* internal  */setBg(): void
        {
            var loc1=null;
            if (this._vo && this._isLoadCom) 
            {
                loc1 = "PetIslandMapDiscardItemBg_" + this._vo.pos.placeType;
                this._bg.bitmapData = GlobalClass.getBitmapData(loc1);
            }
            return;
        }

        /* internal  */onPositionHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandMapShowByPosition, this._vo.pos));
            return;
        }

        /* internal  */onSelectHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandMapDiscardItemSelect, this._vo.placeId));
            return;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            if (!this.contains(this._selectLine)) 
            {
                loc1 = this.getChildIndex(this._bg);
                this.addChildAt(this._selectLine, loc1 + 1);
            }
            return;
        }

        /* internal  */onMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            DisplayUtil.removeMe(this._selectLine);
            return;
        }

        /* internal  */onResCompl(): void
        {
            this._isLoadCom = true;
            ObjCreate.createGBitmap(ImagesConst.PetIslandMapDiscardText_1, 157, 5, this);
            ObjCreate.createGBitmap(ImagesConst.PetIslandMapDiscardText_2, 157, 27, this);
            ObjCreate.createGBitmap(ImagesConst.PetIslandMapDiscardText_3, 337, 5, this);
            ObjCreate.createGBitmap(ImagesConst.PetIslandMapDiscardText_4, 337, 27, this);
            ObjCreate.createGBitmap(ImagesConst.PetIslandMapDiscardItemStateBg, 475, 15, this);
            ObjCreate.createGBitmap(ImagesConst.PetIslandMapDiscardItemState, 476, 16, this);
            this.setBg();
            return;
        }

        protected /* override */ createChildren(): void
        {
            this._bg = ObjCreate.createGBitmap("", 0, 0, this);
            this._name = ObjCreate.createGTextField("", 19, 5, 220, 20, this);
            this._name.mouseEnabled = false;
            this._position = ObjCreate.createGTextField("", 19, 25, 115, 20, this);
            this._position.addEventListener(flash.events.TextEvent.LINK, this.onPositionHandler);
            this._output = ObjCreate.createGTextField("", 223, 5, 220, 20, this);
            this._output.mouseEnabled = false;
            this._time = ObjCreate.createGTextField("", 223, 27, 220, 20, this, GlobalStyle._textFormat5);
            this._time.mouseEnabled = false;
            this._speed = ObjCreate.createGTextField("", 403, 5, 220, 20, this, GlobalStyle._textFormat5);
            this._speed.mouseEnabled = false;
            this._income = ObjCreate.createGTextField("", 403, 27, 220, 20, this);
            this._income.mouseEnabled = false;
            this._selectBtn = ObjCreate.createGButton(Language.getString(28164), 510, 12, 49, 26, this, "ButtonRed");
            this._selectBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSelectHandler);
            this._selectLine = new Object /* flash.display.Sprite */();
            this._selectLine.mouseEnabled = false;
            this._selectLine.graphics.lineStyle(2, 65407, 1);
            this._selectLine.graphics.drawRoundRect(0, 0, 570, 48, 6, 6);
            this._selectLine.graphics.endFill();
            LoaderHelp.addResCallBack(ResFileConst.PetIslandMapDiscard, this.onResCompl);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            return;
        }

        /* internal */ /* var */_name: GTextFiled;

        /* internal */ /* var */_position: GTextFiled;

        /* internal */ /* var */_output: GTextFiled;

        /* internal */ /* var */_time: GTextFiled;

        /* internal */ /* var */_speed: GTextFiled;

        /* internal */ /* var */_income: GTextFiled;

        /* internal */ /* var */_selectBtn: GButton;

        /* internal */ /* var */_bg: GBitmap;

        /* internal */ /* var */_isLoadCom: Boolean;

        /* internal */ /* var */_selectLine: Object /* flash.display.Sprite */;

        /* internal */ /* var */_vo: SPlaceInfo;
    }
